﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Text;
using QZone.crlclr.album.data;
using System.IO;

namespace QZone.crlclr.album
{
    public class PhotosXMLLoader:URLLoader
    {

        public List<Picture> photos;

        public string qqcode;
        public string key;
        public PhotosXMLLoader()
        {
            photos = new List<Picture>();
        }

        /// <summary>
        ///  下载单本相册配置文件;
        /// </summary>
        /// <param name="qqcode"></param>
        /// <param name="key"></param>
        public void loadAlbum(string qqcode, string key)
        {
            photos.Clear();


            this.qqcode=qqcode;
            this.key=key;


            string path=String.Format(QQZoneManager.getPhotosTemplet(), qqcode, key);

            string xmlString = this.load(path);

            xml = new XmlDocument();

            try
            {
                xml.LoadXml(xmlString);
            }
            catch (Exception ex)
            {
                xml.LoadXml(string.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?><error>{0}</error>",ex.Message));
            }

            XmlNodeList list = xml.GetElementsByTagName("pic");

            Picture picture;
            foreach (XmlElement item in list)
            {
                picture = new Picture(qqcode,key);
                picture.bindXML(item);
                photos.Add(picture);

            }
        }

    }
}
